package web;

import javafx.application.Application;
import javafx.application.HostServices;
import javafx.scene.Scene;
import javafx.scene.control.Hyperlink;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

// 打开指定网页
public class OpenWebsiteAccordingToHyperlink extends Application {
	private StackPane root = new StackPane();
	private Hyperlink hyperlink;
	
	public static void main(String[] args) {
		launch(args);
	}
	
	@Override
	public void start(Stage stage) {
		
		hyperlink = new Hyperlink("https://www.hao123.com/");
		root.getChildren().add(hyperlink);
		
		Scene scene = new Scene(root, 300, 200);
		stage.setScene(scene);
		stage.show();
		
		// 事件
		hyperlink.setOnMouseClicked(e -> {
			HostServices host = getHostServices();
			host.showDocument(hyperlink.getText());     // 用默认浏览器打开指定网页
			hyperlink.setVisited(false);	// 设置还没有访问
		});
	}
}
